//
//  ImagePreview.h
//  etionUI
//
//  Created by wangjian on 2/12/14.
//  Copyright (c) 2014 GuangZhouXuanWu. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "ImagePreviewCell.h"

@class CImagePreview;
@protocol CImagePreviewDelegate <NSObject>

@required
- (NSUInteger)numberOfImagesForImagePreview:(CImagePreview *)imagePreview;
- (UIImage *)imagePreview:(CImagePreview *)imagePreview imageAtIndex:(NSUInteger)index;

@optional
//- (UIView *)takeImageViewForImagePreview:(CImagePreview *)imagePreview;

//- (void)imagePreview:(CImagePreview *)imagePreview didClickImageAtIndex:(NSUInteger)index;
- (void)didClickTakeImageViewOfImagePreview:(CImagePreview *)imagePreview;

/**
 *  当删除或增加image，并且growingAutomatic == YES时，image preview的尺寸可能会发生变化
 */
- (void)imagePreviewSizeChange:(CImagePreview *)imagePreview;

// 如果代理没有实现imagePreview:didClickImageAtIndex: 则会在用户点击图片时调用以下代理函数
// 当没有编辑时为查看图片，当编辑时为删除图片，如果will函数返回NO则不执行之后的操作
- (BOOL)imagePreview:(CImagePreview *)imagePreview willShowImageAtIndex:(NSUInteger)index;
- (void)imagePreview:(CImagePreview *)imagePreview didShowImageAtIndex:(NSUInteger)index;
- (BOOL)imagePreview:(CImagePreview *)imagePreview willDeleteImageAtIndex:(NSUInteger)index;
- (void)imagePreview:(CImagePreview *)imagePreview didDeleteImageAtIndex:(NSUInteger)index;

@end

@interface CImagePreview : UIView

@property (nonatomic, assign) id<CImagePreviewDelegate> delegate;

@property (nonatomic, readonly) NSUInteger imageNum;
@property (nonatomic, assign) NSUInteger limitImageNum;     //default 20
@property (nonatomic, assign) BOOL growingAutomatic;        //default YES, grow in vertical
@property (nonatomic, assign) BOOL editable;                //default YES
@property (nonatomic, assign, getter = isEditing) BOOL editing;
@property (nonatomic, assign) BOOL takeImageEnable;         //default YES

/**
 *  minImageSize默认是根据显示宽度计算每排至少3张图片的正方形尺寸,maxImageSize是长宽取view宽度的2/3
 *  当limitImageNum == 1 并且有一张图片是，该图片一般用maxImageSize显示，其他情况用minImageSize，takeImageView也应该用minImageSize
 */
@property (nonatomic, assign) CGSize minImageSize;
@property (nonatomic, assign) CGSize maxImageSize;

- (void)reloadImages;
- (CImagePreviewCell *)cellAtIndex:(NSUInteger)index;
- (void)reloadImageAtIndex:(NSUInteger)index;

- (void)insertImageAtIndex:(NSUInteger)index;
/**
 *  一次插入多张图片
 *
 *  @param indexes NSNumber数组，表示插入位置
 */
- (void)insertImagesAtIndexes:(NSArray *)indexes;
- (void)deleteImageAtIndex:(NSUInteger)index;


@end
